package com.bankcomm.iccard;

import com.bankcomm.R;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;

/**
 * 广播接收器监听音频口插拔
 * add by zhaobin 
 * 
 * **/

public class HeadsetPlugReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(final Context context, Intent intent) {
		if (intent.hasExtra("state")) {
			if (intent.getIntExtra("state", 0) == 0) {
				// 检测到音频拔出
				((BaseActivity) context).sendError(context.getString(R.string.noHeadSet));
				((BaseActivity) context).isAudioAdapterConnect = false;
				((BaseActivity) context).manager = null;
				Message msg = new Message();
				msg.what = 1005;
				Handler handler = EventHandler.ut.eventHandler;
				if (null != handler)
					handler.sendMessage(msg);
			} else if (intent.getIntExtra("state", 0) == 1) {
				// 检测到音频插入
				((BaseActivity) context).isAudioAdapterConnect = true;
				Message msg = new Message();
				msg.what = 1000;
				Handler handler = EventHandler.ut.eventHandler;
				if (null != handler)
					handler.sendMessage(msg);
			}
    	}
	}

}
